﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using Microsoft.Practices.EnterpriseLibrary.Logging;

namespace JTLeigh.Commerce.Spencer.Core.Common
{

	/// <summary>
	/// FIXME
	/// </summary>
	public static class CommonLogEntry
	{

		/// <summary>
		/// Event logged when the connection string for a given database key is either missing or 
		/// invalid.
		/// </summary>
		/// <returns>The <see cref="LogEntry"/>.</returns>
		/// <remarks>
		/// <para>
		/// The operations team should check the /configuration/connectionStrings section of the
		/// application configuration file to ensure an entry exists for the database key.
		/// </para>
		/// <para>
		/// The application functionality that depends on the database will not be available until
		/// this issue is corrected.
		/// </para>
		/// </remarks>
		public static LogEntry MissingInvalidDatabaseConnectionString(Guid tenantId, string databaseKey, Exception exception)
		{
			Dictionary<string, object> properties;

			properties = new Dictionary<string, object>();
			properties.Add("tenantId", tenantId);
			properties.Add("databaseKey", databaseKey);
			properties.Add("exception", exception);

			return new LogEntry(
				String.Format(CultureInfo.InvariantCulture, "The connection string for database key '{0}' is either missing or invalid:\n\n{1}", databaseKey, exception),
				"category", // FIXME
				1, // FIXME: This is an urgent event.  The functionality that depends on the database will be unavailable until this is fixed.
				1, // FIXME
				TraceEventType.Error, 
				"Missing/Invalid Database Connection String",
				properties
				);
		}

	}

}
